package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.ruoyi.common.utils.ShiroUtils.getSysUser;

@Controller
@RequestMapping("/system/user")
public class SysSignController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/sign")
    public String daySign() {
        // 1.取身份信息
        SysUser user = getSysUser();

//        // 2.获取当前日期
//        LocalDateTime now = LocalDateTime.now();
//        String time = now.format(DateTimeFormatter.ofPattern(":yyyy:MM"));
//        // 3.拼接KEY
//        String key = user.getUserId() + time;
//        // 4.获取天数
//        int day = now.getDayOfMonth();
//        // 5.写入Redis setBit key offset value
//        stringRedisTemplate.opsForValue().setBit(key, day-1, true);
//        System.out.println(user.getUserId());
        return null;
    }
}
